<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <!-- vue-router 提供了跳转组件    -->
    <router-link to="/home">首页</router-link>
    <router-link to="/fenlei">分类</router-link>
    <!-- vue-router.js 内置的组件  显示路由切换到的组件 -->
    <router-view></router-view>
  </div>
  <script src="./vue.js"></script>
  <script src="./vue-router.js"></script>
  <script>
    // vue的路由 组件跳转
    // 1.准备组件

    const Home = { //首页组件
      name: "home",
      template: `<div>{{hdata}}</div>`,
      data() {
        return {
          hdata: "我是首页组件"
        }
      }
    }
    const Fenlei = { //分类
      name: "fenlei",
      template: `<div>{{fdata}}</div>`,
      data() {
        return {
          fdata: "我是分类组件"
        }
      }
    }
    // 2. 准备路由的配置项  路由的跳转规则
    const routes = [
      { path: "/home", name: "home", component: Home },
      { path: "/fenlei", name: "fenlei", component: Fenlei }
    ]
    //3. 创建路由对象
    const router = new VueRouter({
      // routes: routes,
      routes
    })
    // 4.把路由对象挂载到vue实例
    var vm = new Vue({
      name: "apps",
      el: "#app",
      router,
    })



  </script>
</body>

</html>